﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace QLKS.Models
{
    static public class TienTeModel
    {
        //
        static public DataTable GetDmTienTe()
        {
            string query = "SELECT * FROM dmTienTe";
            return DataProviderModel.QueryResults(query).Tables[0];
        }

        //Lấy danh sách Tiền tệ
        static public DataTable GetDmTienTe(string selectColumns)
        {
            return DataProviderModel.QueryResults(string.Format("select {0} from dmTienTe", selectColumns.Trim() == "" ? "*" : selectColumns)).Tables[0];
        }

        //Lấy danh sách Tiền tệ
        static public DataTable CreateNewTienTe()
        {
            DataTable tb = DataProviderModel.QueryResults("select * from dmTienTe where 1=0").Tables[0];
            DataRow row = tb.NewRow();
            row["matt"] = "";
            row["tentt"] = "";
            row["tygia"] = 1;
            tb.Rows.Add(row);
            return tb;
        }

        //Create QueryUpdate
        static public string CreateQueryUpdate(string columns)
        {
            string[] listColumns = columns.Split(',');
            string result = string.Empty;
            foreach (string cl in listColumns)
                result += cl + "= @" + cl + ",";
            if (result.Length > 0)
                result = result.Substring(0, result.Length - 1);
            return result;
        }

        //Thêm nhân viên
        static public int ThemTienTe(DataTable tb)
        {
            string matt = tb.Rows[0]["matt"].ToString();
            if (GetDmTienTe("matt").Select("matt ='" + matt + "'").Length <= 0)
                return DataProviderModel.Insert(tb, "dmTienTe", "");
            else
                return DataProviderModel.Update(tb, "dmTienTe", "matt");
        }

        //Xóa Tiền tệ
        static public int XoaTienTe(string matt)
        {
            DataTable tb = new DataTable();
            tb.Columns.Add("matt");
            tb.Rows.Add(matt);
            return DataProviderModel.Detele(tb, "dmTienTe");
        }
    }
}
